package Model;

import java.awt.Point;
import java.util.ArrayList;
import java.util.Observable;

/**
 * Holds all GameData in any given puzzle game
 * Reduces the # of dependencies of the controller
 * -Created Class(Feb 11,2011)
 * Samual Martelli
 * </pre>
 */
public class GameData {


	private Player playerOfGame;
	private ArrayList<Monster> gameMonsters;
	private Maze gameMaze;


	public GameData(Player newPlayer, 
			ArrayList<Monster> newMonsters,Maze newMaze){
			playerOfGame = newPlayer;
			gameMonsters = newMonsters;
			gameMaze = newMaze;
	}
	//returns a string representation of the maze
	public String printMaze(){
		   /* Places the game in text form
	        */
	        String string = "";
	        for (int x = 0; x < Maze.MAP_SIZE; x++) {
	            for (int y = 0; y < Maze.MAP_SIZE; y++) {
	            	Point p = new Point(x,y);
	                if (p == playerOfGame.getCoordinate()) {
	                    string += "P";
	                } 
	                else if (gameMaze.getMazeItem(p) == Maze.ITEM_SPACE) {
	                    string += "O";
	                }
	                else if (gameMaze.getMazeItem(p) == Maze.PORTAL_SPACE) {
	                    string += "U";
	                }
	                else if (gameMaze.getMazeItem(p) == Maze.RAT_TUNNEL_SPACE) {
	                    string += "U";
	                }
	                else if (gameMaze.getMazeItem(p) == Maze.EXIT_SPACE) {
	                    string += "Exit->";
	                }
	                else if (gameMaze.getMazeItem(p) == Maze.TRAP_SPACE) {
	                    string += "!";
	                }
	                else if (gameMaze.getMazeItem(p) == Maze.HEDGE_SPACE) {
	                    string += "{}";
	                }
	                else if (gameMaze.getMazeItem(p) == Maze.WALL_SPACE) {
	                    string += "W";
	                }
	                else {
	                	for (Monster gm: gameMonsters){
	                		if (p == gm.getCoordinate() && !(gm instanceof RunningBunny)) {
	    	                    string += "M";
	    	                } else if (p == gm.getCoordinate()){
	    	                	string += "B";
	    	                }
	        	            
	        	        }
	                    string += " ";
	                }
	            }
	        }
	        string += "\n";
       return string;
		
	}
	
	public boolean isMonsterAt(Point p){
		for (Monster gm: gameMonsters){
			if(p.equals(gm.coordinates)){
				return true;//he is here
			}
		}
		return false;//nope
	}
	
	public boolean isPlayerAt(Point p){
		if(p.equals(playerOfGame.coordinates)){
			return true; //yes
		}
		return false;//nope
	}
	

	public Player getPlayerOfGame() {
		return playerOfGame;
	}

	public ArrayList<Monster> getMonsters() {
		return gameMonsters;
	}
	
	public Maze getGameMaze(){
		return gameMaze;
	}
	
	//add a new monster to the list
	public void addMonster(Monster newGuy){
		gameMonsters.add(newGuy);
	}
	
	//remove one that dies
	public void removeMonster(Monster deadGuy){
		gameMonsters.remove(deadGuy);
	}
	
	//gets rid of all monsters
	public void removeMonsters(){
		gameMonsters.clear();
	}
	
	

	
	
}
